package com.avic.system.common.util;

import com.avic.system.common.util.ex.BizErrorCode;
import com.avic.system.common.util.ex.BizException;
import org.apache.commons.lang3.StringUtils;

/**
 * @author: huangsheng
 * @date: 2018/4/11
 */
public final class AssertUtil {

    /**
     * 校验参数是否为空
     */
    public static void isNotBlank(String str, String description) {
        if (StringUtils.isBlank(str)) {
            throw new BizException(BizErrorCode.PARAM_ERROR, description);
        }
    }

    /**
     * 校验参数是否为空
     */
    public static void isNotBlank(String str) {
        if (StringUtils.isBlank(str)) {
            throw new BizException(BizErrorCode.PARAM_ERROR, BizErrorCode.PARAM_ERROR.getDescription());
        }
    }

    /**
     * 校验对象是否为空
     *
     * @param object
     * @param errorCodeEnum
     */
    public static void isNotNull(Object object, BizErrorCode errorCodeEnum) {
        if (object == null) {
            throw new BizException(errorCodeEnum, errorCodeEnum.getDescription());
        }
    }

    /**
     * 校验对象是否为空
     *
     * @param object
     * @param errorCodeEnum
     */
    public static void isNotNull(Object object, BizErrorCode errorCodeEnum, String description) {
        if (object == null) {
            throw new BizException(errorCodeEnum, description);
        }
    }

    /**
     * isTrue
     *
     * @param value
     * @param errorCodeEnum
     * @param description
     */
    public static void isTrue(boolean value, BizErrorCode errorCodeEnum, String description) {
        if (!value) {
            throw new BizException(errorCodeEnum, description);
        }
    }

    /**
     * isTrue
     *
     * @param value
     * @param errorCodeEnum
     */
    public static void isTrue(boolean value, BizErrorCode errorCodeEnum) {
        if (!value) {
            throw new BizException(errorCodeEnum, errorCodeEnum.getDescription());
        }
    }
}
